<html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8">
	<title>美拓blog --利用google LocalSearch 批量获取区域坐标</title>
		<script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
	<style type="text/css" media="screen"> 
/*
Theme Name: meito 
Theme URI: http://blog.meituo.net
Version: 1.1
Author: 独孤逸辰
Author URI: http://blog.meituo.net
Description: A simple wordpress theme
Tags: white,two-columns,custom-header
*/
 
body,h1,h2,h3,p,blockquote,dl,dt,dd,ul,ol,li,button,input,textarea {margin: 0; padding: 0;}
body {font:13px Tahoma, Helvetica, Arial, "\5b8b\4f53", sans-serif;}
h1,h2,h3,h4,h5 {font-size: 14px; font-family:"微软雅黑";}
h1{padding-left:20px;}
 
a {text-decoration:none; color:#04a;}
 
ol,ul {list-style:none;}
 
#page_content {width:910px;}
#main {min-height:450px;height:450px !important;height:450px;}
 
::selection {
    background: #C5E7F6; //Safari
}
::-moz-selection {
    background: #C5E7F6; //Firefox
}
	
#sidebar {width:200px;float:left; background:#fafafa;}
blockquote {border:1px dashed #54bafb; background:#fafafa; padding:10px 10px 0; margin:10px;}
p,textarea,.content li,#sidebar a,.fn,.post_class li,#page_content,#post_metadata,#cancel_comment_reply,#footer  {line-height:20px;}
.fn,#top li a,#nav li a,#rss_icon,#rss_google,#rss_xianguo {display:block;}
.post_class ul,#commentform,.comment-body p,.reply,#cancel_comment_reply,.children {margin-left:90px;}
.comment-author,#respond h3,#post_metadata h3,.post_class h3,#comments h3 {width:75px; text-align:right; padding-right:10px;}
h2,.comment-body,#page_content dl,#page_content dt,.post_nav,.post_class,#comments,.navigation,.comment_list {margin-bottom:10px;}
.comment_list li li,#respond,#footer {margin-top:10px;}
#top{overflow:hidden;}
#top,#top a {color:#fff;}
#top h1{float:left}
#top h4{float:right;font-size:12px;padding-right:20px;margin:0;}
#search,#page_content,#top ul,#rss,.alignright ,.content {float:right;}
.w970,.page,.navigation,.post_nav,.linkcat,.post_class,#post_metadata,.comment_list li,#respond ,.post {overflow:hidden; zoom:1;}
#header{overflow: hidden;zoom:1;}
#header,#nav {background:#f6f6f6;}
#top,#footer {background:#303536;}
#top {height:28px; line-height:28px;}
#top ul {margin-right:1px;}
#top li a,#nav li a {padding-left:10px; padding-right:10px;}
 
#top li a:hover {text-decoration:none; background:#000;}
.current_page_item,#top li.current_page_item a:hover {background:#6C7676;}
#nav  h2 {border-bottom:1px solid #e6e6e6; border-top:1px solid #fff;margin:0 auto;color:#54BAFB;}
 
#nav {height:34px; line-height:34px;
	text-align:center;
}
pre{
	background:#EFFFFF none repeat scroll 0 0;
border:1px solid #C0C0C0;
padding:10px;
}
.pre{
	background:#EFFFFF none repeat scroll 0 0;
border:1px solid #C0C0C0;
padding:10px;
}
#footer {text-align:right; border-top:1px solid #0C0E0E; padding:8px 20px; color:#fff;}
</style>
 
</head>
<body>
	
<div id="top">
	<h1><a href="http://blog.meituo.net">美拓blog</a></h1>
	<h4>返回原文：<a href="http://blog.meituo.net/2010/09/23/%E5%88%A9%E7%94%A8google-localsearch-%E6%89%B9%E9%87%8F%E8%8E%B7%E5%8F%96%E5%8C%BA%E5%9F%9F%E5%9D%90%E6%A0%87/">利用google LocalSearch 批量获取区域坐标</a></h4>
</div>
 
<div id="nav">
	<h2><a href="http://blog.meituo.net">利用google LocalSearch 批量获取区域坐标</a></h2>
</div>
<div style="text-align:center;padding-top:20px;">
	<div id="sidebar">
		<h3></h3>
	</div>
	<div class="main" style="margin:0 auto"><input type="button" value="点击获取坐标" style="padding:10 20px;font-size:20px;" onclick="run()"/></div>
	<div class="main" style="margin:0 auto;padding:20px;text-align:left;width:800px;">
		<h4>获得一下坐标</h4>
<pre>
var zuobiao = {
	'海淀区':[
		'中关村','紫竹桥','上地'
	],
	'朝阳区':[
		'望京','国贸','十里堡'
	],
	'丰台区':[
		'丰台体育馆','新发地'
	]
}
</pre>
		<h4>测试代码：</h4>
		<div id="relcon" class="pre"></div>
	</div>
 
<script src="http://www.google.com/jsapi?key=ABQIAAAAeO99B_Z_KRhiN6QAh8d3exRf_TBDXjwfhkTEYEa8w2SU_8LnthS7jDrOrwEmjub3ESjCujooKFLxIg" type="text/javascript"></script>
<script type="text/javascript"> 
    google.load('search', '1');
   // google.load('maps', '2');
</script>
 
<script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js" type="text/javascript"></script>
<script> 
var latlng = {},  //存储经纬度
	k = 0,
	empty = [], //存储查找不到的区域名
	$con = $("#relcon");
function getlocation(location,obj){
    var localsearch = new google.search.LocalSearch();
    localsearch.setSearchCompleteCallback(window, function(a,b){
    	if(!!localsearch.results[0]){
	            obj['lat'] = localsearch.results[0].lat;
	            obj['lng'] = localsearch.results[0].lng;
	            var string = location + ":lat:" +obj['lat'] +",lng:"+obj['lng']+"<br />";
                $con.append(string);
        }else{
        	empty.push(location);
        }           
    });
   localsearch.execute(location);
  }
  
//获取zuobiao的经纬度
var zuobiao = {
	'深圳市':[
		'福田区'
	]
}
function run(){
	for (var i in zuobiao){
			latlng[i]={};
	        latlng[i]['title'] = i;
	        setTimeout(function(){
	            getlocation(i,latlng[i]);
	        },k);
	        k = k+1000; 
	     //  getlocation(i,latlng[i]);
		for(var j in zuobiao[i]){
	            latlng[zuobiao[i][j]] = {};
	            latlng[zuobiao[i][j]]['title'] = zuobiao[i][j];
	            setTimeout(function(){
	                getlocation(i+latlng[zuobiao[i][j]]['title'],latlng[zuobiao[i][j]]);
	            },k);
	            k = k+1000; 
		}
	}
}
</script>
 
</div>
<div id="footer">
	<div>&copy;2008-2010 美拓blog All Rights Reservied   <script src="http://s87.cnzz.com/stat.php?id=1761092&web_id=1761092&show=pic" language="JavaScript"></script></div>
</div>
</body>
</html>
